﻿using Kevin.Shop.Business.Core.Components;
using Kevin.Shop.Business.Core.Components.Responser;
using Kevin.Shop.Business.Service.Entity.FinanceManagement.Balance;
using Kevin.Shop.Business.Service.Entity.Helper;
using RiderShop.Mobile.Common.Component;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RiderShop.Mobile.Modle.MyAccount
{
    public class BalanceModel
    {
        public BalanceAccount BalanceAccount { get; set; }

        public List<BalanceIncomeHistory> BalanceIncomeHistory { get; set; }

        public string ErrorMessage { get; set; }


        public List<UserPaymentCard> GetUserPaymentCardList(int userId)
        {
            var list = RestfulHelper.Query<UserPaymentCard>(SiteUrl.FormatUrl("FinanceManagement_GetUserPaymentCard", userId, true));

            return list;
        }


        public void GetUserBalanceAccount(int userId)
        {
            this.BalanceAccount = RestfulHelper.QueryWithSingle<BalanceAccount>(SiteUrl.FormatUrl("FinanceManagement_GetUserBalanceAccount", userId));

            var query = new Pagination()
            {
                UserId = userId,
                PageIndex = 0,
                PageSize = 35,
                BeginDate = DateTime.Now.AddMonths(-1),
                EndDate = DateTime.Now
            };

            DbQueryResult<List<BalanceIncomeHistory>> result = RestfulHelper.Query<BalanceIncomeHistory>(SiteUrl.FormatUrl("FinanceManagement_GetBalanceIncomeHistory"), query);
            this.BalanceIncomeHistory = result.Data ?? new List<BalanceIncomeHistory>();


        }

        public ServiceResponser UpdateUserPaymentCard(string card, string password, int userId)
        {
            UserPaymentCard paymentCard = new UserPaymentCard()
            {
                UserId = userId,
                CardNumber = card,
                Password = password,
                EditUser = userId,
                EditDate = DateTime.Now
            };
            var response = RestfulHelper.Update<UserPaymentCard>(SiteUrl.FormatUrl("FinanceManagement_UpdateUserPaymentCard"), paymentCard);
            return response;
        }
    }
}
